﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.DALFactory;
using KPIS.DBM;


namespace KPIS.GERP.GHRMS.BLL
{
    public class SalaryTypeBLL : ISalaryTypeBLL
    {
       // private static readonly IInquireDAL DAL = DataAccess.CreateInquire();
        // private InquireInfo inquireInfo = new InquireInfo();

        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        public DataSet ListSalaryType()
        {
            dbManager.CreateParameters(1);
            dbManager.AddParameters(0, "@RecordStatus", SystemInfo._ActiveRecordStatus);

            DataSet ds = new DataSet();
            dbManager.Open();
            ds = dbManager.ExecuteDataSet(CommandType.Text, "select * from hrm_pr_salary_group_dtls where record_status = @RecordStatus");
            dbManager.Dispose();
            //return DAL.ListInquire(new InquireInfo(0));
            return ds;
        }

        public DataSet ListSalaryType(string id)
        {
            dbManager.CreateParameters(2);
            dbManager.AddParameters(0, "@RecordStatus", SystemInfo._ActiveRecordStatus);
            dbManager.AddParameters(1, "@id", id);

            DataSet ds = new DataSet();
            dbManager.Open();
            ds = dbManager.ExecuteDataSet(CommandType.Text, "select * from hrm_pr_salary_group_dtls where sal_grp_seq=@id and record_status = @RecordStatus");
            dbManager.Dispose();
            //return DAL.ListInquire(new InquireInfo(0));
            return ds;
        }

        public void Insert(string sal_grp_seq, double sal_min, double sal_max, double sal_tmp, string CreatedBy)
        {
            try
            {
                dbManager.CreateParameters(7);
                dbManager.AddParameters(0, "@sal_min", sal_min);
                dbManager.AddParameters(1, "@sal_max", sal_max);
                dbManager.AddParameters(2, "@sal_tmp", sal_tmp);
                dbManager.AddParameters(3, "@RecordStatus", SystemInfo._ActiveRecordStatus);
                dbManager.AddParameters(4, "@CreatedBy", CreatedBy);
                dbManager.AddParameters(5, "@CreatedWhen", DateTime.Today);
                dbManager.AddParameters(6, "@sal_grp_seq", sal_grp_seq);

                dbManager.Open();
                dbManager.ExecuteNonQuery(CommandType.Text, "INSERT INTO hrm_pr_salary_group_dtls (sal_grp_seq,sal_min, sal_max, sal_tmp,record_status,created_by,created_when) VALUES (@sal_grp_seq, @sal_min, @sal_max, @sal_tmp, @RecordStatus,@CreatedBy,@CreatedWhen)");
                dbManager.Dispose();
            }
            catch
            {
                throw;
            }
        }

        public void Update(int Sequence, double sal_min, double sal_max, double sal_tmp, string UpdateBy)
        {
            try
            {
                dbManager.CreateParameters(7);
                dbManager.AddParameters(0, "@sequence", Sequence);
                dbManager.AddParameters(1, "@sal_min", sal_min);
                dbManager.AddParameters(2, "@sal_max", sal_max);
                dbManager.AddParameters(3, "@sal_tmp", sal_tmp);
                dbManager.AddParameters(4, "@RecordStatus", SystemInfo._ActiveRecordStatus);
                dbManager.AddParameters(5, "@updated_by", UpdateBy);
                dbManager.AddParameters(6, "@updated_when", DateTime.Today);
                dbManager.Open();

                dbManager.ExecuteNonQuery(CommandType.Text, "UPDATE hrm_pr_salary_group_dtls SET sal_min=@sal_min, sal_max=@sal_max,sal_tmp=@sal_tmp,record_status=@RecordStatus,updated_by=@updated_by,updated_when=@updated_when WHERE grp_dtls_seq=@sequence");
                dbManager.Dispose();
            }
            catch
            {
                throw;
            }
        }
        public void Delete(int Sequence, string UpdateBy)
        {
            try
            {
                dbManager.CreateParameters(4);
                dbManager.AddParameters(0, "@sequence", Sequence);
                dbManager.AddParameters(1, "@record_status", SystemInfo._DeleteRecordStatus);
                dbManager.AddParameters(2, "@updated_by", UpdateBy);
                dbManager.AddParameters(3, "@updated_when", DateTime.Today);
                dbManager.Open();
                dbManager.ExecuteNonQuery(CommandType.Text, "UPDATE hrm_pr_salary_group_dtls SET RECORD_STATUS=@record_status,updated_by=@updated_by, updated_when=@updated_when WHERE grp_dtls_seq=@sequence");
                dbManager.Dispose();
            }
            catch
            {
                throw;
            }
        }
        
    }
}
